<link href="__STATIC__/zui/lib/uploader/zui.uploader.min.css" rel="stylesheet">
<form action="{$info['id'] == null?url('add'):url('edit')}" class="form-edit" enctype="multipart/form-data" method="post">
    <div class="row">
        <div class="col-md-6">
            <div class="form-group">
                <label class="required">标识</label>
                <div>
                    <input type="text" class="form-control" name="name" value="{$info.name|default=''}">
                </div>

            </div>
        </div>
        <div class="col-md-6">
            <div class="form-group">
                <label class="required">标题</label>
                <div>
                    <input type="text" class="form-control" name="title" value="{$info.title|default=''}">
                </div>

            </div>
        </div>
        <div class="col-md-12">
            <div class="form-group">
                <label>附件
                    <small class="text-danger">( 上传文件大小不能超过{$upload_config.size/1048576}MB,
                        支持的文件格式有{$upload_config.ext} )
                    </small>
                </label>

                <div id="myUploader" class="uploader">
                    <input id="file-attachment" type="hidden" name="attachment" value="{$info.attachment}"/>
                    <div class="uploader-message text-center">
                        <div class="content"></div>
                        <button type="button" class="close">×</button>
                    </div>
                    <div class="file-list" data-drag-placeholder="请拖拽文件到此处"></div>
                    <div id="tip-message" class="uploader-status pull-right text-muted"></div>
                    <button type="button" class="btn btn-primary uploader-btn-browse"><i
                            class="icon icon-cloud-upload"></i> 选择文件
                    </button>
                </div>
            </div>
        </div>
        <div class="col-md-12">
            <div class="form-group">
                <label>备注说明</label>
                <div>
                    <textarea name="remark" class="form-control" rows="2">{$info.remark|default=''}</textarea>
                </div>
            </div>

        </div>

    </div>
    <hr style="margin-top: 0; margin-bottom: 15px; margin-left: -15px; margin-right: -15px;"/>
    <div class="text-right">
        <input type="hidden" name="id" value="{$info.id|default=''}">

        <button type="button" class="btn btn-default" data-dismiss="modal">
            <i class="icon icon-times"></i> 关闭
        </button>
        <button class="btn btn-primary ajax-post" type="submit" data-href="form-edit">
            <i class="icon icon-save"></i> 保存
        </button>
    </div>
</form>
<script src="__STATIC__/zui/lib/uploader/zui.uploader.min.js"></script>
<script>
    $(function () {

        var options = {
            // 初始化选项
            url: '{:url("file/upload")}',
            autoUpload: true,
            uploadedMessage: false,
            limitFilesCount: 1,
            rename: false,
            filters: {
                max_file_size: '{$upload_config.size}',
                prevent_duplicates: true,
                mime_types: [
                    {title: '附件', extensions: '{$upload_config.ext}'},
                ],

            },
            staticFiles: [
                {volist name = "info['attachments']" id = "attachment"}
                {name: '{$attachment.name}', size: '{$attachment.size}'},
                {/volist}
            ],
            deleteActionOnDone: function (file, doRemoveFile) {
                doRemoveFile();
                var file_value = new Array();
                $('#myUploader').find('.file').each(function () {
                    var value = $(this).attr('data-value');
                    file_value.push(value);
                });
                return true;
            },
            responseHandler: function (responseObject, file) {
                //console.log(responseObject);
                var response = JSON.parse(responseObject.response);
                if (response.result == 'ok') {
                    $('#file-' + file.id).attr('data-value', response.id);
                    var file_value = new Array();
                    $('#myUploader').find('.file').each(function () {
                        var value = $(this).attr('data-value');
                        file_value.push(value);
                    });
                    $('#file-attachment').val(file_value.toString());
                }
            }
        };
        var $uploader = $('#myUploader').uploader(options);
    });
</script>




